package com.cloudsea.yunhaistores.controller;


import com.cloudsea.yunhaistores.dto.SubmitOrderDTO;
import com.cloudsea.yunhaistores.service.OrderService;
import com.cloudsea.yunhaistores.vo.PaymentQRCodeVO;
import com.cloudsea.yunhaiutils.common.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户-订单管理", description = "用户在完成购物车选择后，进行订单的提交与创建")
@RestController
@RequestMapping("/orders")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Operation(summary = "提交购物车并创建订单", description = "用户在购物车页面点击“去结算”后，小程序调用此接口，后端将根据会话ID自动拉取购物车内容并创建待支付订单")
    @PostMapping("/submit")
    public ApiResponse<PaymentQRCodeVO> submitOrder(@Valid @RequestBody SubmitOrderDTO dto) {
        PaymentQRCodeVO paymentInfo = orderService.submitOrder(dto);
        return ApiResponse.success("订单创建成功，请支付", paymentInfo);
    }
}
